
import React, { useState } from 'react';
import { Select, Form } from 'antd';
import request from '@/utils/request';

const apiURL = "/api/services/app/Warehse/";
export interface SelectProps {
    width?: number,
    cRef?: any,
    name?: any,
    label?: string,
    showSearch?: boolean,
    placeholder?: string,
    required?: boolean,
}
const WhseSelect: React.FC<SelectProps> = (props: SelectProps) => {
    const [dataSource, setDataSource] = useState<any[]>([]);
    React.useEffect(() => {
        request(apiURL + 'GetAll', {
            method: 'GET'
        }).then((response) => {
            if (response) {
                if (response.success) {
                    setDataSource(response.result.items)
                }
            }
        });
    }, [])
    return (
        <Form.Item name={props.name} label={props.label} rules={[{ required: props.required, message: props.placeholder + "必填" }]}>
            <Select
                showSearch={props.showSearch}
                placeholder={props.placeholder}
                filterOption={(input, option: any) =>
                    option.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
                }
                style={{ width: props.width }}>
                {
                    dataSource?.map((item: any) => {
                        return (<Select.Option key={item.warehouseCode} value={item.warehouseCode}>{item.description}</Select.Option>)
                    })
                }
            </Select>
        </Form.Item>
    )
}
export default WhseSelect;